#import "TabBarController.h"
#import "MainPageViewController.h"
#import "DiscoverViewController.h"
#import "WritingPostViewController.h"
#import "SettingViewController.h"
#import "SidePageViewController.h"
#import <Masonry/Masonry.h>
#import "UIViewController+MMDrawerController.h"
#import "MMDrawerBarButtonItem.h"

@interface TabBarController ()
@property (nonatomic, strong) UIButton *fixedButton;
@end

@implementation TabBarController


- (void)viewDidLoad
{
    [super viewDidLoad];
    /* 创建转场动画 */
    CATransition *transition = [CATransition animation];
    transition.duration = 1.0; // 动画时间
    transition.type = kCATransitionFade; // 动画样式
    transition.subtype = kCATransitionFromRight; // 动画方向
        
    /* 页面切换 */
    
    MainPageViewController *mainPage = [[MainPageViewController alloc]init];
    UINavigationController *mainPageNav = [[UINavigationController alloc]initWithRootViewController:mainPage];
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:mainPage animated:NO]; // 注意这里 animated 必须设置为 NO
    mainPageNav.navigationBar.translucent = NO;
    
    DiscoverViewController *discoverPage = [[DiscoverViewController alloc]init];
    [discoverPage loadData];
    UINavigationController *discoverNav = [[UINavigationController alloc]initWithRootViewController:discoverPage];
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:discoverPage animated:NO];
    discoverNav.navigationBar.translucent = NO;
    
    SettingViewController * setVC = [[SettingViewController alloc] init];
    UINavigationController * setNav = [[UINavigationController alloc] initWithRootViewController:setVC];
    setNav.navigationBar.translucent = NO;
    [self.navigationController.view.layer addAnimation:transition forKey:kCATransition];
    [self.navigationController pushViewController:setVC animated:NO];
    self.tabBar.translucent = NO;
    self.viewControllers = @[mainPageNav, discoverNav,setNav];
}

/**
 *  加载控制器的时候设置打开抽屉模式  (因为在后面会关闭)
 */
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    //设置打开抽屉模式
    [self.mm_drawerController setOpenDrawerGestureModeMask:MMOpenDrawerGestureModeAll];
}

- (void)didReceiveMemoryWarning{
    [super didReceiveMemoryWarning];
}

-(void)leftBtn{
     //这里的话是通过遍历循环拿到之前在AppDelegate中声明的那个MMDrawerController属性，然后判断是否为打开状态，如果是就关闭，否就是打开(初略解释，里面还有一些条件)
    [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}
-(void)rightBtn{
    [self.mm_drawerController toggleDrawerSide:MMDrawerSideRight animated:YES completion:nil];
}

/**
 *  添加点击手势  一个手指双击
 */
-(void)doubleTap:(UITapGestureRecognizer*)gesture{
    [self.mm_drawerController bouncePreviewForDrawerSide:MMDrawerSideLeft completion:nil];
}

/**
 *  添加点击手势  两个个手指双击
 */
-(void)twoFingerDoubleTap:(UITapGestureRecognizer*)gesture{
    [self.mm_drawerController bouncePreviewForDrawerSide:MMDrawerSideRight completion:nil];
}



@end
